//
//  EWOrderInfoCell.m
//  haveSomethingToEat
//
//  Created by 陈 宁权 on 2017/7/27.
//  Copyright © 2017年 陈 宁权. All rights reserved.
//

#import "EWOrderInfoCell.h"

@interface EWOrderInfoCell()
@property(nonatomic,strong) UIView *underLine;
@end

@implementation EWOrderInfoCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"EWOrderInfoCell";
    EWOrderInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[EWOrderInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupChildViews];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setupChildViews
{
    UIView *backgroundView = [[UIView alloc] init];
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self addSubview:backgroundView];
    
    _logoView = [[UIImageView alloc] init];
    _logoView.tintColor = [UIColor blackColor];
    [backgroundView addSubview:_logoView];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 0;
    _titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
    _titleLabel.font = [UIFont systemFontOfSize:13];
    [backgroundView addSubview:_titleLabel];
    
    _underLine = [[UIView alloc] init];
    _underLine.backgroundColor = [UIColor colorWithRed:0.94 green:0.95 blue:0.95 alpha:1.00];
    _underLine.hidden = YES;
    [backgroundView addSubview:_underLine];
    
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.bottom.equalTo(self);
        make.left.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
    }];
    
    [_logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backgroundView);
        make.left.equalTo(backgroundView).offset(10);
        make.width.offset(17);
        make.height.offset(17);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView);
        make.bottom.equalTo(backgroundView);
        make.left.equalTo(_logoView.mas_right).offset(10);
        make.right.equalTo(backgroundView).offset(-15);
    }];
    
    [_underLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView.mas_bottom).offset(-0.5);
        make.left.equalTo(_logoView);
        make.right.equalTo(_titleLabel);
        make.height.offset(1);
    }];
}

- (void)setNeedUnderLine:(BOOL)needUnderLine
{
    _needUnderLine = needUnderLine;
    if (_needUnderLine) {
        _underLine.hidden = NO;
    }
}

@end
